<?php

class LogController extends EController
{

	public $layout = 'main';
	
	//过滤器
	public function filters()
	{
		return array(
			array(
				'application.filters.BackEndAuthRequestFilter -send',
			)
		);
	}




	
	//新闻管理
	public function actionlist()
	{

        $cookie = new CHttpCookie('articlehttpbor', str_replace("/admin/","",$_SERVER["REQUEST_URI"]));
        $cookie->expire = time()+60*60*24*30;
        Yii::app()->request->cookies['articlehttpbor']=$cookie;
        $this->layout='list';
        $this->son_menu=0; //头部的子菜单

        $act_list=ActionMenuHelper::getHiddenMenu();

        $model=new ShopCardLog('search');
        $model->unsetAttributes();

        if(isset($_GET['ShopCardLog']))
            $model->attributes=$_GET['ShopCardLog'];
        $this->render('list',array(
                'dataProvider'=>$model->search(),
                'act_list'=>$act_list,
                'model'=>$model)
        );
	}

    public function getRandNo(){
        return  date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
    }

	public function actionadd(){


        $this->layout='list';
        $this->son_menu=1;
        $model = new LogAddForm;
        $model->order_no = $this->getRandNo();
        //ajax 验证
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'ajax_form') {
            echo CActiveForm::validate($model);
            Yii::app()->end();

        }

        if(isset($_POST['LogAddForm']))
        {

            $model->attributes=$_POST['LogAddForm'];
            // 验证用户输入，并在判断输入正确后重定向到
            if($model->validate())
            {
                if($model->add())
                {
                    $this->showMessage(Yii::t('info','operation success'),'aiunify/log/list');
                }
                else
                {
                    $this->showMessage(Yii::t('info','operation failed'),'aiunify/log/list');
                }
            }
        }
        $this->render('add',array('model'=>$model));
    }

    public function actiondiscard(){
	    $id = $this->_getId();
        $log = ShopCardLog::model()->findByPk($id);
        $log ->status = 2 ;
        if ($log->save())
        {
            $this->showMessage(Yii::t('info','operation success'));
        }
        else
        {
            $this->showMessage(Yii::t('info','operation failed'));
        }
    }



    //获取id
    private function _getId(){
        if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
            throw new CHttpException(400,'Invalid request. admin_id is required!');
        }
        return $_GET['id'];
    }
}
